package com.dfbz.demo;

import java.io.ByteArrayInputStream;
import java.io.PushbackInputStream;

/**
 * @author lscl
 * @version 1.0
 * @intro:
 */
public class Demo07_回退流的小案例 {
    public static void main(String[] args)throws Exception {
        String str = "13079016067131350454961897434920916552444009";

        // 从内存中读取数据
        PushbackInputStream push = new PushbackInputStream(new ByteArrayInputStream(str.getBytes()));

        System.out.println("读取之后的数据为：");

        int data;
        int count = 1;

        while ((data = push.read()) != -1) {    // 读取内容

            System.out.print((char) data);
            if (count % 11 == 0) {                          // 读完了一个手机号
                push.unread("-".getBytes());                // 放回到缓冲区之中
                data = push.read();    // 再读一遍
                System.out.print((char) data);              // 13079016067-131350454
            }

            count++;
        }

        System.out.println();
    }
}
